package scut.carson_ho.database_demo;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MyLook extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.data_look);
        findId();
        selectSQL();

    }
    private EditText outname, outkind, outbirth, checkName;
    TextView  back;

    private void findId() {
        outname = findViewById(R.id.name);
        outkind = findViewById(R.id.kind);
        outbirth = findViewById(R.id.birth);
        back=findViewById(R.id.back);

        back.setOnClickListener(two);


    }
    private Intent intent;
//    private Intent intent2=getIntent();

    private void selectSQL(){
        String name=getIntent().getStringExtra("1");
        SQLiteDatabase d = openOrCreateDatabase("user.db", MODE_PRIVATE, null);
//        d.execSQL("CREATE TABLE IF NOT EXISTS user (name text PRIMARY KEY AUTOINCREMENT,kind varchar(40),birth varhcar(40))");
        try{
        Cursor cursor = d.query("user", new String[]{"name, kind, birth"}, "name=?", new String[]{name}, null, null, null);

        cursor.moveToFirst();
        outname.setText(name);
        outkind.setText(cursor.getString(cursor.getColumnIndex("birth")));
        outbirth.setText(cursor.getString(cursor.getColumnIndex("kind")));
        cursor.close();
        }catch (Exception e){
            outname.setText("");
            outkind.setText("");
            outbirth.setText("");
            Toast.makeText(MyLook.this,"没有该信息",Toast.LENGTH_SHORT).show();
        }

    }
    View.OnClickListener two = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            intent= new Intent(MyLook.this,MyData.class);
            startActivity(intent);

        }
    };
}
